﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Shop.Page.Models;
using PetaPoco;

namespace Shop.Page.Repositories
{
    /// <summary>
    /// 数据访问层
    /// </summary>
    public class HomeBottomAccess
    {
        private Database DB = new Database("ConnString");
        /// <summary>
        /// 根据类型获取底部信息
        /// </summary>
        /// <param name="Type">0主标题1子链接</param>
        /// <returns></returns>
        public IList<HomeBottom> GetHomeBottomInfoByType(int Type)
        {
            Sql sql = Sql.Builder.Append("select * from Shop_HomeBottom where Type = @0", Type);
            return DB.Fetch<HomeBottom>(sql);
        }
        /// <summary>
        /// 根据所述父级获取信息
        /// </summary>
        /// <param name="Superior"></param>
        /// <returns></returns>
        public IList<HomeBottom> GetHomeBottomInfoBySuperior(int Superior)
        {
            Sql sql = Sql.Builder.Append("select * from Shop_HomeBottom where Superior = @0 and Type = 1 Order by OrderTime desc", Superior);
            return DB.Fetch<HomeBottom>(sql);
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="hinfo"></param>
        /// <returns></returns>
        public object AddHomeBottomInfo(HomeBottom hinfo)
        {
            return DB.Insert("Shop_HomeBottom", "HBID", hinfo);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="hinfo"></param>
        /// <returns></returns>
        public int UpdateHomeBottomInfo(HomeBottom hinfo)
        {
            Sql sql = Sql.Builder.Append("update Shop_HomeBottom set HBName = @0,HBHref = @1,Superior =@2 where HBID = @3", hinfo.HBName,hinfo.HBHref,hinfo.Superior,hinfo.HBID);
            return DB.Execute(sql);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="HBID"></param>
        /// <returns></returns>
        public int DelHomeBottomInfo(int HBID)
        {
            Sql sql = Sql.Builder.Append("delete from Shop_HomeBottom where HBID = @0", HBID);
            return DB.Execute(sql);
        }
        /// <summary>
        /// 置顶
        /// </summary>
        /// <param name="HBID"></param>
        /// <returns></returns>
        public int Order(int HBID)
        {
            Sql sql = Sql.Builder.Append("update Shop_HomeBottom set OrderTime = getdate() where HBID = @0",HBID);
            return DB.Execute(sql);
        }
    }
}
